package com.etennis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etennis.pojos.PageResult;
import com.etennis.mapper.MemberMapper;
import com.etennis.mapper.RecordMapper;
import com.etennis.pojos.dto.web.MemberPageQueryDTO;
import com.etennis.pojos.dto.web.RecordsPageQueryDTO;
import com.etennis.pojos.entity.Member;
import com.etennis.pojos.entity.Record;
import com.etennis.pojos.vo.web.MemberVO;
import com.etennis.pojos.vo.web.RecordsVO;
import com.etennis.service.IMediaService;
import com.etennis.service.IMemberService;
import com.etennis.service.IRecordService;
import com.etennis.utils.BeanCopyUtils;
import com.etennis.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.stream.Collectors;

@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements IRecordService {
    @Autowired
    MemberMapper memberMapper;
    @Autowired
    IMemberService iMemberService;
    @Autowired
    RecordMapper recordMapper;

    @Override
    public PageResult<RecordsVO> pageMember(RecordsPageQueryDTO recordsPageQueryDTO) {
        MemberPageQueryDTO memberPageQueryDTO = BeanCopyUtils.copyBean(recordsPageQueryDTO,MemberPageQueryDTO.class);
        PageResult<MemberVO> pageRes=iMemberService.pageMember(memberPageQueryDTO);
        PageResult<RecordsVO> res=new PageResult<>();
        res.setTotal(pageRes.getTotal());
        res.setRecords(pageRes.getRecords().stream().map(each -> {
            // todo 胜盘率、胜场率、总盘数、总局数
            RecordsVO recordsVO = new RecordsVO();
            recordsVO.setMemberId(each.getId());
            recordsVO.setMemberName(each.getName());
            recordsVO.setScore(each.getScore());
            recordsVO.setMatchCount(10);
            recordsVO.setWinMatchRate(46);
            recordsVO.setSetCount(25);
            recordsVO.setWinSetRate(58);
            return recordsVO;
        }).collect(Collectors.toList()));
       return res;
    }
}
